//    Copyright (C) 2013  <lugocreation@gmail.com>
//
//    This program is free software: you can redistribute it and/or modify
//    it under the terms of the GNU General Public License as published by
//    the Free Software Foundation, either version 3 of the License, or
//    (at your option) any later version.
//
//    This program is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//    GNU General Public License for more details.
//
//    You should have received a copy of the GNU General Public License
//    along with this program.  If not, see <http://www.gnu.org/licenses/>
package org.jpgolay.wi.realestate;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ResourceBundle;
import java.util.Vector;
import javax.swing.*;
import javax.swing.border.LineBorder;
import javax.swing.border.TitledBorder;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.swing.table.*;
import org.jpgolay.gui.date.DateComboBox;
import org.jpgolay.gui.iconBar.IconBar;
import org.jpgolay.wi.util.WIDate;

public class RealEstateListGUI extends JInternalFrame {

    private class TableModel extends AbstractTableModel {

        public int getColumnCount() {
            return colonnes.size();
        }

        public int getRowCount() {
            return rangees.size() / getColumnCount();
        }

        public String getColumnName(int col) {
            String colName = "";
            if (col <= getColumnCount()) {
                colName = (String) colonnes.elementAt(col);
            }
            return colName;
        }

        public Class getColumnClass(int col) {
            if (col == 2 || col == 4 || col == 5 || col == 6 || col == 7 || col == 8 || col == 9 || col == 11) {
                return java.lang.String.class;
            }
            if (col == 10) {
                return java.lang.Object.class;
            } else {
                return java.lang.Number.class;
            }
        }

        public boolean isCellEditable(int row, int col) {
            return false;
        }

        public Object getValueAt(int row, int col) {
            if (col == 8 || col == 9) {
                return date.toPlain((String) rangees.elementAt(row * getColumnCount() + col));
            }
            if (col == 10) {
                return null;
            }
            if (col == 11) {
                if (rangees.elementAt(row * getColumnCount() + col) == null) {
                    return null;
                } else {
                    return "<html><font color=red>" + date.toPlain((String) rangees.elementAt(row * getColumnCount() + col));
                }
            }
            if (col == 13) {
                if (rangees.elementAt(row * getColumnCount() + col).toString().equals("oui")) {
                    return null;
                }
                if (rangees.elementAt(row * getColumnCount() + col).toString().equals("non")) {
                    return null;
                } else {
                    return (String) rangees.elementAt(row * getColumnCount() + col);
                }
            }
            if (col == 14) {
                return null;
            } else {
                return (String) rangees.elementAt(row * getColumnCount() + col);
            }
        }

        public void setValueAt(Object obj, int i, int j) {
        }

        TableModel() {
        }
    }

    public class OptionCellRenderer extends DefaultTableCellRenderer {

        public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int col) {
            Component comp = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, col);
            label = (JLabel) comp;
            if (rangees.elementAt(row * myModel.getColumnCount() + col).toString().equals("oui")) {
                label.setIcon(optionIcon);
            } else {
                label.setIcon(null);
            }
            return label;
        }
        protected Icon optionIcon;
        protected JLabel label;

        public OptionCellRenderer() {
            optionIcon = new ImageIcon(getClass().getResource("/org/jpgolay/wi/images/croix.png"));
        }
    }

    public class PhotoCellRenderer extends DefaultTableCellRenderer {

        public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int col) {
            Component comp = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, col);
            label = (JLabel) comp;
            if (rangees.elementAt(row * myModel.getColumnCount() + col).toString().equals("oui")) {
                label.setIcon(photoIcon);
            } else {
                label.setIcon(null);
            }
            return label;
        }
        protected Icon photoIcon;
        protected JLabel label;

        public PhotoCellRenderer() {
            photoIcon = new ImageIcon(getClass().getResource("/org/jpgolay/wi/images/photo.png"));
        }
    }

    public class MeubleCellRenderer extends DefaultTableCellRenderer {

        public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int col) {
            Component comp = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, col);
            label = (JLabel) comp;
            if (rangees.elementAt(row * myModel.getColumnCount() + col).toString().equals("oui")) {
                label.setIcon(meubleIcon);
            } else {
                label.setIcon(null);
            }
            return label;
        }
        protected Icon meubleIcon;
        protected JLabel label;

        public MeubleCellRenderer() {
            meubleIcon = new ImageIcon(getClass().getResource("/org/jpgolay/wi/images/meuble.png"));
        }
    }

    public class LabelCellRenderer extends DefaultTableCellRenderer {

        public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int col) {
            Component comp = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, col);
            label = (JLabel) comp;
            return label;
        }
        protected JLabel label;

        public LabelCellRenderer() {
        }
    }

    public RealEstateListGUI() {
        law = false;
        setFrameIcon(new ImageIcon(getClass().getResource("/org/jpgolay/wi/images/liste_bien.png")));
        date = new WIDate();
        alternateColor = new Color(200, 250, 200);
        lightGreen = new ImageIcon(getClass().getResource("/org/jpgolay/wi/images/vert.png"));
        darkGreen = new ImageIcon(getClass().getResource("/org/jpgolay/wi/images/darkvert.png"));
        lightRed = new ImageIcon(getClass().getResource("/org/jpgolay/wi/images/rouge.png"));
        darkRed = new ImageIcon(getClass().getResource("/org/jpgolay/wi/images/darkrouge.png"));
        lightYellow = new ImageIcon(getClass().getResource("/org/jpgolay/wi/images/jaune.png"));
        darkYellow = new ImageIcon(getClass().getResource("/org/jpgolay/wi/images/darkjaune.png"));
        lightOrange = new ImageIcon(getClass().getResource("/org/jpgolay/wi/images/orange.png"));
        darkOrange = new ImageIcon(getClass().getResource("/org/jpgolay/wi/images/darkorange.png"));
        initComponents();
    }

    private void initComponents() {
        buttonGroup1 = new ButtonGroup();
        iconBar1 = new IconBar();
        liste = new JPanel();
        recherche = new JPanel();
        rechercheTP = new JTabbedPane();
        simple = new JPanel();
        categorieL = new JLabel();
        genreL = new JLabel();
        typeL = new JLabel();
        secteurL = new JLabel();
        optionL = new JLabel();
        reserveL = new JLabel();
        meubleL = new JLabel();
        prixL = new JLabel();
        categorieCB = new JComboBox();
        genreCB = new JComboBox();
        typeCB = new JComboBox();
        secteurCB = new JComboBox();
        optionCB = new JComboBox();
        reserveCB = new JComboBox();
        meubleCB = new JComboBox();
        prixCB = new JComboBox();
        avancee = new JPanel();
        standingL = new JLabel();
        parkingL = new JLabel();
        garageL = new JLabel();
        cuisineL = new JLabel();
        jardinL = new JLabel();
        piscineL = new JLabel();
        visibiliteL = new JLabel();
        archiveL = new JLabel();
        standingCB = new JComboBox();
        parkingCB = new JComboBox();
        garageCB = new JComboBox();
        cuisineCB = new JComboBox();
        jardinCB = new JComboBox();
        piscineCB = new JComboBox();
        visibiliteCB = new JComboBox();
        archiveCB = new JComboBox();
        disponibiliteP = new JPanel();
        disponibiliteCB = new JComboBox();
        duL = new JLabel();
        dateDuF = new DateComboBox();
        auL = new JLabel();
        dateAuF = new DateComboBox();
        actionP = new JPanel();
        archiveP = new JPanel();
        archiveTrueRB = new JRadioButton();
        archiveFalseRB = new JRadioButton();
        infosP = new JPanel();
        infosL = new JLabel();
        visibiliteP = new JPanel();
        visibilityCB = new JComboBox();
        fields = new JPanel();
        selectCB = new JComboBox();
        selectF = new JTextField();
        orderByCB = new JComboBox();
        searchB = new JButton();
        initB = new JButton();
        jScrollPane1 = new JScrollPane();
        resultat = new JTable() {
            public Component prepareRenderer(TableCellRenderer renderer, int rowIndex, int vColIndex) {
                Component c = super.prepareRenderer(renderer, rowIndex, vColIndex);
                if (rowIndex % 2 == 0) {
                    c.setBackground(alternateColor);
                } else {
                    c.setBackground(getBackground());
                }
                return c;
            }
        };
        resultat.setShowHorizontalLines(false);
        optionRenderer = new OptionCellRenderer();
        optionRenderer.setHorizontalAlignment(0);
        photoRenderer = new PhotoCellRenderer();
        photoRenderer.setHorizontalAlignment(0);
        meubleRenderer = new MeubleCellRenderer();
        meubleRenderer.setHorizontalAlignment(4);
        labelRenderer = new LabelCellRenderer();
        labelRenderer.setHorizontalAlignment(0);
        jMenuBar1 = new JMenuBar();
        options = new JMenu();
        newMI = new JMenuItem();
        openMI = new JMenuItem();
        saveMI = new JMenuItem();
        modifyMI = new JMenuItem();
        deleteMI = new JMenuItem();
        printMI = new JMenuItem();
        helpMI = new JMenuItem();
        setTitle(ResourceBundle.getBundle("org/jpgolay/wi/wii").getString("realestate_list_title"));
        iconBar1.setEnabledCreate(false);
        iconBar1.setEnabledHelp(true);
        iconBar1.setEnabledModify(false);
        iconBar1.setEnabledOpen(false);
        iconBar1.setEnabledRemove(false);
        iconBar1.setEnabledSave(false);
        getContentPane().add(iconBar1, "North");
        liste.setLayout(new BorderLayout());
        recherche.setLayout(new BorderLayout());
        rechercheTP.setTabPlacement(3);
        simple.setLayout(null);
        simple.setSize(new Dimension(818, 45));
        simple.setPreferredSize(new Dimension(818, 45));
        simple.setMaximumSize(new Dimension(818, 45));
        categorieL.setHorizontalAlignment(0);
        categorieL.setText("Cat\351gorie");
        categorieL.setSize(new Dimension(100, 22));
        categorieL.setLocation(2, 2);
        simple.add(categorieL, null);
        genreL.setHorizontalAlignment(0);
        genreL.setText("Genre");
        genreL.setSize(new Dimension(100, 22));
        genreL.setLocation(104, 2);
        simple.add(genreL, null);
        typeL.setHorizontalAlignment(0);
        typeL.setText("Type");
        typeL.setSize(new Dimension(100, 22));
        typeL.setLocation(206, 2);
        simple.add(typeL, null);
        secteurL.setHorizontalAlignment(0);
        secteurL.setText("Secteur");
        secteurL.setSize(new Dimension(100, 22));
        secteurL.setLocation(308, 2);
        simple.add(secteurL, null);
        optionL.setHorizontalAlignment(0);
        optionL.setText("Option");
        optionL.setSize(new Dimension(100, 22));
        optionL.setLocation(410, 2);
        simple.add(optionL, null);
        reserveL.setHorizontalAlignment(0);
        reserveL.setText("R\351sev\351");
        reserveL.setSize(new Dimension(100, 22));
        reserveL.setLocation(512, 2);
        simple.add(reserveL, null);
        meubleL.setHorizontalAlignment(0);
        meubleL.setText("Meubl\351");
        meubleL.setSize(new Dimension(100, 22));
        meubleL.setLocation(614, 2);
        simple.add(meubleL, null);
        prixL.setHorizontalAlignment(0);
        prixL.setText("Prix");
        prixL.setSize(new Dimension(100, 22));
        prixL.setLocation(716, 2);
        simple.add(prixL, null);
        categorieCB.setModel(new DefaultComboBoxModel(new String[]{
                    "indiff\351rente", "location", "vente", "vill\351giature"
                }));
        categorieCB.setSelectedItem("location");
        categorieCB.setSize(new Dimension(100, 22));
        categorieCB.setLocation(2, 23);
        categorieCB.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                categorieCBActionPerformed(evt);
            }
        });
        simple.add(categorieCB, null);
        genreCB.setModel(new DefaultComboBoxModel(new String[]{
                    "indiff\351rent", "appartement", "maison", "local commercial", "garage", "parking", "divers"
                }));
        genreCB.setSize(new Dimension(100, 22));
        genreCB.setLocation(104, 23);
        simple.add(genreCB, null);
        typeCB.setModel(new DefaultComboBoxModel(new String[]{
                    "indiff\351rent", "studio", "T1", "T1bis", "T2", "T3", "T4", "T5", "T6", ">T6",
                    "autre"
                }));
        typeCB.setSize(new Dimension(100, 22));
        typeCB.setLocation(206, 23);
        simple.add(typeCB, null);
        secteurCB.setModel(new DefaultComboBoxModel(new String[]{
                    "indiff\351rent", "Nord", "Sud", "Est", "Ouest", "Centre"
                }));
        secteurCB.setSize(new Dimension(100, 22));
        secteurCB.setLocation(308, 23);
        simple.add(secteurCB, null);
        optionCB.setModel(new DefaultComboBoxModel(new String[]{
                    "indiff\351rent", "oui", "non"
                }));
        optionCB.setSize(new Dimension(100, 22));
        optionCB.setLocation(410, 23);
        simple.add(optionCB, null);
        reserveCB.setModel(new DefaultComboBoxModel(new String[]{
                    "indiff\351rent", "oui", "non"
                }));
        reserveCB.setSize(new Dimension(100, 22));
        reserveCB.setLocation(512, 23);
        simple.add(reserveCB, null);
        meubleCB.setModel(new DefaultComboBoxModel(new String[]{
                    "indiff\351rent", "oui", "non"
                }));
        meubleCB.setSize(new Dimension(100, 22));
        meubleCB.setLocation(614, 23);
        simple.add(meubleCB, null);
        prixCB.setModel(new DefaultComboBoxModel(new String[]{
                    "indiff\351rent", "400", "600", "800", "1000", "1500", "2000"
                }));
        prixCB.setEnabled(false);
        prixCB.setSize(new Dimension(100, 22));
        prixCB.setLocation(716, 23);
        simple.add(prixCB, null);
        JPanel simpleP = new JPanel();
        simpleP.setBorder(new LineBorder(new Color(51, 255, 51), 1));
        simpleP.setLayout(new FlowLayout(1, 1, 1));
        simpleP.add(simple);
        rechercheTP.addTab("Recherche simple", lightGreen, simpleP);
        avancee.setLayout(null);
        avancee.setSize(new Dimension(818, 45));
        avancee.setPreferredSize(new Dimension(818, 45));
        avancee.setMaximumSize(new Dimension(818, 45));
        standingL.setHorizontalAlignment(0);
        standingL.setText("Standing");
        standingL.setSize(new Dimension(100, 22));
        standingL.setLocation(2, 2);
        avancee.add(standingL);
        parkingL.setHorizontalAlignment(0);
        parkingL.setText("Parking");
        parkingL.setSize(new Dimension(100, 22));
        parkingL.setLocation(104, 2);
        avancee.add(parkingL);
        garageL.setHorizontalAlignment(0);
        garageL.setText("Garage");
        garageL.setSize(new Dimension(100, 22));
        garageL.setLocation(206, 2);
        avancee.add(garageL);
        cuisineL.setHorizontalAlignment(0);
        cuisineL.setText("Cuisine");
        cuisineL.setSize(new Dimension(100, 22));
        cuisineL.setLocation(308, 2);
        avancee.add(cuisineL);
        jardinL.setHorizontalAlignment(0);
        jardinL.setText("Jardin");
        jardinL.setSize(new Dimension(100, 22));
        jardinL.setLocation(410, 2);
        avancee.add(jardinL);
        piscineL.setHorizontalAlignment(0);
        piscineL.setText("Piscine");
        piscineL.setSize(new Dimension(100, 22));
        piscineL.setLocation(512, 2);
        avancee.add(piscineL);
        visibiliteL.setHorizontalAlignment(0);
        visibiliteL.setText("Visibilit\351");
        visibiliteL.setSize(new Dimension(100, 22));
        visibiliteL.setLocation(614, 2);
        avancee.add(visibiliteL);
        archiveL.setHorizontalAlignment(0);
        archiveL.setText("Archive");
        archiveL.setSize(new Dimension(100, 22));
        archiveL.setLocation(716, 2);
        avancee.add(archiveL);
        standingCB.setModel(new DefaultComboBoxModel(new String[]{
                    "indiff\351rent", "normal", "bon", "tr\350s bon", "exceptionnel"
                }));
        standingCB.setSize(new Dimension(100, 22));
        standingCB.setLocation(2, 23);
        avancee.add(standingCB);
        parkingCB.setModel(new DefaultComboBoxModel(new String[]{
                    "indiff\351rent", "oui"
                }));
        parkingCB.setSize(new Dimension(100, 22));
        parkingCB.setLocation(104, 23);
        avancee.add(parkingCB);
        garageCB.setModel(new DefaultComboBoxModel(new String[]{
                    "indiff\351rent", "oui"
                }));
        garageCB.setSize(new Dimension(100, 22));
        garageCB.setLocation(206, 23);
        avancee.add(garageCB);
        cuisineCB.setModel(new DefaultComboBoxModel(new String[]{
                    "indiff\351rent", "\351quip\351e", "non \351quip\351e"
                }));
        cuisineCB.setSize(new Dimension(100, 22));
        cuisineCB.setLocation(308, 23);
        avancee.add(cuisineCB);
        jardinCB.setModel(new DefaultComboBoxModel(new String[]{
                    "indiff\351rent", "oui", "non"
                }));
        jardinCB.setSize(new Dimension(100, 22));
        jardinCB.setLocation(410, 23);
        avancee.add(jardinCB);
        piscineCB.setModel(new DefaultComboBoxModel(new String[]{
                    "indiff\351rent", "oui", "non"
                }));
        piscineCB.setSize(new Dimension(100, 22));
        piscineCB.setLocation(512, 23);
        avancee.add(piscineCB);
        visibiliteCB.setModel(new DefaultComboBoxModel(new String[]{
                    "indiff\351rent", "agence", "portail", "site"
                }));
        visibiliteCB.setSize(new Dimension(100, 22));
        visibiliteCB.setLocation(614, 23);
        avancee.add(visibiliteCB);
        archiveCB.setModel(new DefaultComboBoxModel(new String[]{
                    "indiff\351rent", "oui", "non"
                }));
        archiveCB.setSize(new Dimension(100, 22));
        archiveCB.setLocation(716, 23);
        archiveCB.setSelectedIndex(2);
        avancee.add(archiveCB);
        JPanel advanceP = new JPanel();
        advanceP.setBorder(new LineBorder(new Color(255, 51, 0), 1));
        advanceP.setLayout(new FlowLayout(1, 1, 1));
        advanceP.add(avancee);
        rechercheTP.addTab("Recherche avanc\351e", darkRed, advanceP);
        disponibiliteP.setLayout(new FlowLayout(1));
        disponibiliteCB.setModel(new DefaultComboBoxModel(new String[]{
                    "indiff\351rente", "Disponibilit\351", "D\351part souhait\351", "D\351part accept\351"
                }));
        disponibiliteCB.setPreferredSize(new Dimension(150, 22));
        disponibiliteCB.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                disponibiliteCBActionPerformed(evt);
            }
        });
        disponibiliteP.add(disponibiliteCB);
        duL.setHorizontalAlignment(0);
        duL.setText("DU");
        duL.setPreferredSize(new Dimension(50, 22));
        disponibiliteP.add(duL);
        dateDuF.setEditable(false);
        dateDuF.setEnabled(false);
        dateDuF.setPreferredSize(new Dimension(150, 22));
        disponibiliteP.add(dateDuF);
        auL.setHorizontalAlignment(0);
        auL.setText("AU");
        auL.setPreferredSize(new Dimension(50, 22));
        disponibiliteP.add(auL);
        dateAuF.setEditable(false);
        dateAuF.setEnabled(false);
        dateAuF.setPreferredSize(new Dimension(150, 22));
        disponibiliteP.add(dateAuF);
        JPanel availabilityP = new JPanel();
        availabilityP.setBorder(new LineBorder(new Color(255, 255, 0), 1));
        availabilityP.setLayout(new FlowLayout(1, 1, 1));
        availabilityP.add(disponibiliteP);
        rechercheTP.addTab("Crit\350res de disponibilit\351", darkYellow, availabilityP);
        actionP.setLayout(new BorderLayout());
        actionP.setBorder(new LineBorder(new Color(255, 204, 51), 1));
        archiveP.setLayout(new GridLayout(1, 2));
        archiveP.setBorder(new TitledBorder("Archive"));
        archiveTrueRB.setText("oui");
        buttonGroup1.add(archiveTrueRB);
        archiveP.add(archiveTrueRB);
        archiveFalseRB.setSelected(true);
        archiveFalseRB.setText("non");
        buttonGroup1.add(archiveFalseRB);
        archiveP.add(archiveFalseRB);
        actionP.add(archiveP, "East");
        infosP.setBorder(new TitledBorder("Num\351ro de Fiche"));
        infosL.setHorizontalAlignment(0);
        infosP.add(infosL);
        actionP.add(infosP, "Center");
        visibiliteP.setLayout(new GridLayout(1, 1));
        visibiliteP.setBorder(new TitledBorder("Visibilit\351"));
        visibilityCB.setModel(new DefaultComboBoxModel(new String[]{
                    "agence", "portail", "site"
                }));
        visibiliteP.add(visibilityCB);
        actionP.add(visibiliteP, "West");
        rechercheTP.addTab("Modifier visible et archive", darkOrange, actionP);
        recherche.add(rechercheTP, "Center");
        FlowLayout flowLayout6 = new FlowLayout();
        flowLayout6.setHgap(2);
        flowLayout6.setVgap(2);
        flowLayout6.setAlignment(1);
        fields.setLayout(flowLayout6);
        fields.setBorder(new LineBorder(new Color(51, 255, 51), 1));
        selectCB.setModel(new DefaultComboBoxModel(new String[]{
                    "Num\351ro de fiche", "Num\351ro de lot", "R\351f\351rence", "R\351sidence"
                }));
        selectCB.setPreferredSize(new Dimension(150, 22));
        selectCB.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                selectF.setText("");
            }
        });
        fields.add(selectCB);
        selectF.setPreferredSize(new Dimension(150, 22));
        fields.add(selectF);
        orderByCB.setModel(new DefaultComboBoxModel(new String[]{
                    "Classement par TYPE", "Classement par num\351ro de FICHE", "Classement par num\351ro de LOT", "Classement par PRIX (<)", "Classement par R\351f\351rence"
                }));
        orderByCB.setPreferredSize(new Dimension(250, 22));
        fields.add(orderByCB);
        searchB.setIcon(new ImageIcon(getClass().getResource("/org/jpgolay/wi/images/loupe.png")));
        searchB.setPreferredSize(new Dimension(50, 22));
        searchB.setContentAreaFilled(false);
        searchB.setBorderPainted(false);
        searchB.setFocusPainted(false);
        searchB.setToolTipText("Lancer la recherche");
        fields.add(searchB);
        initB.setIcon(new ImageIcon(getClass().getResource("/org/jpgolay/gui/images/modify.png")));
        initB.setToolTipText("R\351initialiser les crit\350res de recherche");
        initB.setPreferredSize(new Dimension(22, 22));
        initB.setContentAreaFilled(false);
        initB.setBorderPainted(false);
        initB.setFocusPainted(false);
        initB.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                initBActionPerformed(evt);
            }
        });
        fields.add(initB);
        recherche.add(fields, "South");
        liste.add(recherche, "North");
        myModel = new TableModel();
        jScrollPane1.setViewportView(resultat);
        liste.add(jScrollPane1, "Center");
        getContentPane().add(liste, "Center");
        options.setMnemonic('O');
        options.setText(ResourceBundle.getBundle("org/jpgolay/wi/wii").getString("Options"));
        newMI.setAccelerator(KeyStroke.getKeyStroke(78, 2));
        newMI.setText(ResourceBundle.getBundle("org/jpgolay/wi/wii").getString("new"));
        newMI.setIcon(new ImageIcon(getClass().getResource("/org/jpgolay/gui/images/new.png")));
        newMI.setEnabled(false);
        options.add(newMI);
        openMI.setAccelerator(KeyStroke.getKeyStroke(79, 2));
        openMI.setText(ResourceBundle.getBundle("org/jpgolay/wi/wii").getString("open"));
        openMI.setIcon(new ImageIcon(getClass().getResource("/org/jpgolay/gui/images/open.png")));
        openMI.setEnabled(false);
        options.add(openMI);
        saveMI.setAccelerator(KeyStroke.getKeyStroke(83, 2));
        saveMI.setText(ResourceBundle.getBundle("org/jpgolay/wi/wii").getString("save"));
        saveMI.setIcon(new ImageIcon(getClass().getResource("/org/jpgolay/gui/images/save.png")));
        saveMI.setEnabled(false);
        options.add(saveMI);
        modifyMI.setAccelerator(KeyStroke.getKeyStroke(77, 2));
        modifyMI.setText(ResourceBundle.getBundle("org/jpgolay/wi/wii").getString("modify"));
        modifyMI.setIcon(new ImageIcon(getClass().getResource("/org/jpgolay/gui/images/modify.png")));
        modifyMI.setEnabled(false);
        options.add(modifyMI);
        deleteMI.setAccelerator(KeyStroke.getKeyStroke(88, 2));
        deleteMI.setText(ResourceBundle.getBundle("org/jpgolay/wi/wii").getString("delete"));
        deleteMI.setIcon(new ImageIcon(getClass().getResource("/org/jpgolay/gui/images/delete.png")));
        deleteMI.setEnabled(false);
        options.add(deleteMI);
        printMI.setAccelerator(KeyStroke.getKeyStroke(80, 2));
        printMI.setText(ResourceBundle.getBundle("org/jpgolay/wi/wii").getString("print"));
        printMI.setIcon(new ImageIcon(getClass().getResource("/org/jpgolay/gui/images/printer.png")));
        options.add(printMI);
        helpMI.setAccelerator(KeyStroke.getKeyStroke(112, 0));
        helpMI.setText(ResourceBundle.getBundle("org/jpgolay/wi/wii").getString("help"));
        helpMI.setIcon(new ImageIcon(getClass().getResource("/org/jpgolay/gui/images/help.png")));
        options.add(helpMI);
        jMenuBar1.add(options);
        setJMenuBar(jMenuBar1);
        searchB.requestFocusInWindow();
        rechercheTP.addChangeListener(new ChangeListener() {
            public void stateChanged(ChangeEvent evt) {
                rechercheTPStateChanged(evt);
            }
        });
        pack();
    }

    private void rechercheTPStateChanged(ChangeEvent evt) {
        if (rechercheTP.getSelectedIndex() == 3 && law) {
            saveMI.setEnabled(true);
            iconBar1.setEnabledSave(true);
        } else {
            saveMI.setEnabled(false);
            iconBar1.setEnabledSave(false);
        }
        switch (rechercheTP.getSelectedIndex()) {
            case 0: // '\0'
                fields.setBorder(new LineBorder(new Color(51, 255, 51), 1));
                rechercheTP.setIconAt(0, lightGreen);
                rechercheTP.setIconAt(1, darkRed);
                rechercheTP.setIconAt(2, darkYellow);
                rechercheTP.setIconAt(3, darkOrange);
                break;

            case 1: // '\001'
                fields.setBorder(new LineBorder(new Color(255, 51, 0), 1));
                rechercheTP.setIconAt(0, darkGreen);
                rechercheTP.setIconAt(1, lightRed);
                rechercheTP.setIconAt(2, darkYellow);
                rechercheTP.setIconAt(3, darkOrange);
                break;

            case 2: // '\002'
                fields.setBorder(new LineBorder(new Color(255, 255, 0), 1));
                rechercheTP.setIconAt(0, darkGreen);
                rechercheTP.setIconAt(1, darkRed);
                rechercheTP.setIconAt(2, lightYellow);
                rechercheTP.setIconAt(3, darkOrange);
                break;

            case 3: // '\003'
                fields.setBorder(new LineBorder(new Color(255, 204, 51), 1));
                rechercheTP.setIconAt(0, darkGreen);
                rechercheTP.setIconAt(1, darkRed);
                rechercheTP.setIconAt(2, darkYellow);
                rechercheTP.setIconAt(3, lightOrange);
                break;
        }
    }

    private void disponibiliteCBActionPerformed(ActionEvent evt) {
        if (disponibiliteCB.getSelectedIndex() == 0) {
            dateDuF.setEditable(false);
            dateAuF.setEditable(false);
            dateDuF.setEnabled(false);
            dateAuF.setEnabled(false);
        } else {
            dateDuF.setEditable(true);
            dateAuF.setEditable(true);
            dateDuF.setEnabled(true);
            dateAuF.setEnabled(true);
        }
    }

    private void categorieCBActionPerformed(ActionEvent evt) {
        switch (categorieCB.getSelectedIndex()) {
            case 0: // '\0'
                prixCB.setEnabled(false);
                break;

            case 1: // '\001'
                prixCB.setModel(new DefaultComboBoxModel(rentPrice));
                prixCB.setEnabled(true);
                break;

            case 2: // '\002'
                prixCB.setModel(new DefaultComboBoxModel(salePrice));
                prixCB.setEnabled(true);
                break;

            case 3: // '\003'
                prixCB.setModel(new DefaultComboBoxModel(rentPrice));
                prixCB.setEnabled(true);
                break;
        }
    }

    private void initBActionPerformed(ActionEvent evt) {
        initComboBox();
    }

    private void tableModele() {
        TableColumn column = new TableColumn();
        for (int i = 0; i < 15; i++) {
            column = resultat.getColumnModel().getColumn(i);
            if (i == 0) {
                column.setPreferredWidth(15);
            } else if (i == 1) {
                column.setPreferredWidth(15);
            } else if (i == 2) {
                column.setPreferredWidth(15);
            } else if (i == 3) {
                column.setPreferredWidth(60);
            } else if (i == 4) {
                column.setPreferredWidth(15);
            } else if (i == 5) {
                column.setPreferredWidth(15);
            } else if (i == 6) {
                column.setPreferredWidth(70);
            } else if (i == 7) {
                column.setPreferredWidth(70);
            } else if (i == 8) {
                column.setPreferredWidth(50);
            } else if (i == 9) {
                column.setPreferredWidth(50);
            } else if (i == 10) {
                column.setPreferredWidth(8);
            } else if (i == 11) {
                column.setPreferredWidth(50);
            } else if (i == 12) {
                column.setPreferredWidth(40);
            } else if (i == 13) {
                column.setPreferredWidth(40);
            } else {
                column.setPreferredWidth(8);
            }
        }

    }

    private void initComboBox() {
        typeCB.setSelectedIndex(0);
        prixCB.setSelectedIndex(0);
        disponibiliteCB.setSelectedIndex(0);
        genreCB.setSelectedIndex(0);
        secteurCB.setSelectedIndex(0);
        categorieCB.setSelectedIndex(0);
        standingCB.setSelectedIndex(0);
        parkingCB.setSelectedIndex(0);
        garageCB.setSelectedIndex(0);
        visibiliteCB.setSelectedIndex(0);
        archiveCB.setSelectedIndex(2);
        cuisineCB.setSelectedIndex(0);
        jardinCB.setSelectedIndex(0);
        piscineCB.setSelectedIndex(0);
        meubleCB.setSelectedIndex(0);
        orderByCB.setSelectedIndex(0);
        optionCB.setSelectedIndex(0);
        reserveCB.setSelectedIndex(0);
        selectF.setText("");
        dateDuF.setModel(new DefaultComboBoxModel(new String[]{
                    ""
                }));
        dateAuF.setModel(new DefaultComboBoxModel(new String[]{
                    ""
                }));
    }

    public String getActionArchive() {
        if (archiveTrueRB.isSelected()) {
            return "T";
        } else {
            return "F";
        }
    }

    public void setActionArchive(String archive) {
        if (archive.equals("T")) {
            archiveTrueRB.setSelected(true);
        } else {
            archiveFalseRB.setSelected(true);
        }
    }

    public String getVisibility() {
        return (String) visibilityCB.getSelectedItem();
    }

    public void setVisibility(String visibility) {
        visibilityCB.setSelectedItem(visibility);
    }

    public void setInfosL(String infos) {
        infosL.setText(infos);
    }

    public JButton getSearchB() {
        return searchB;
    }

    public String getCategorie() {
        return (String) categorieCB.getSelectedItem();
    }

    public String getSecteur() {
        return (String) secteurCB.getSelectedItem();
    }

    public String getGenre() {
        return (String) genreCB.getSelectedItem();
    }

    public String getDisponibilite() {
        String result = "indiff\351rente";
        switch (disponibiliteCB.getSelectedIndex()) {
            case 1: // '\001'
                result = "AVAILABILITY";
                break;

            case 2: // '\002'
                result = "DEPARTURE_CUSTOMER";
                break;

            case 3: // '\003'
                result = "DEPARTURE";
                break;
        }
        return result;
    }

    public String getDateDu() {
        return (String) dateDuF.getSelectedItem();
    }

    public String getDateAu() {
        return (String) dateAuF.getSelectedItem();
    }

    public String getPrix() {
        return (String) prixCB.getSelectedItem();
    }

    public String getType() {
        return (String) typeCB.getSelectedItem();
    }

    public String getArchive() {
        if (archiveCB.getSelectedIndex() == 2) {
            return "F";
        }
        if (archiveCB.getSelectedIndex() == 1) {
            return "T";
        } else {
            return (String) archiveCB.getSelectedItem();
        }
    }

    public String getCuisine() {
        return (String) cuisineCB.getSelectedItem();
    }

    public String getGarage() {
        return (String) garageCB.getSelectedItem();
    }

    public String getJardin() {
        return (String) jardinCB.getSelectedItem();
    }

    public String getParking() {
        return (String) parkingCB.getSelectedItem();
    }

    public String getPiscine() {
        return (String) piscineCB.getSelectedItem();
    }

    public String getStanding() {
        return (String) standingCB.getSelectedItem();
    }

    public String getVisibilite() {
        return (String) visibiliteCB.getSelectedItem();
    }

    public String getOption() {
        return (String) optionCB.getSelectedItem();
    }

    public String getReserve() {
        return (String) reserveCB.getSelectedItem();
    }

    public JTable getResultat() {
        return resultat;
    }

    public Vector getRangees() {
        return rangees;
    }

    public void setRangees(Vector rangees) {
        this.rangees = rangees;
    }

    public Vector getColonnes() {
        return colonnes;
    }

    public void setColonnes(Vector colonnes) {
        this.colonnes = colonnes;
    }

    public JMenuItem getPrintMI() {
        return printMI;
    }

    public JMenuItem getHelpMI() {
        return helpMI;
    }

    public JMenuItem getSaveMI() {
        return saveMI;
    }

    public IconBar getIconBar() {
        return iconBar1;
    }

    public String getSelect() {
        return selectF.getText();
    }

    public JTextField getSelectF() {
        return selectF;
    }

    public int getSelectType() {
        return selectCB.getSelectedIndex();
    }

    public String getMeuble() {
        return (String) meubleCB.getSelectedItem();
    }

    public String getOrderBy() {
        String s = "TYPE";
        switch (orderByCB.getSelectedIndex()) {
            case 1: // '\001'
                s = "ID";
                break;

            case 2: // '\002'
                s = "BATCH";
                break;

            case 3: // '\003'
                s = "PRICE";
                break;

            case 4: // '\004'
                s = "REF_INTERNAL";
                break;
        }
        return s;
    }

    public void refreshTable() {
        myModel = new TableModel();
        resultat.setModel(myModel);
        tableModele();
        jScrollPane1.setViewportView(resultat);
        TableColumnModel model = resultat.getColumnModel();
        model.getColumn(1).setCellRenderer(labelRenderer);
        model.getColumn(2).setCellRenderer(labelRenderer);
        model.getColumn(8).setCellRenderer(labelRenderer);
        model.getColumn(9).setCellRenderer(labelRenderer);
        model.getColumn(10).setCellRenderer(optionRenderer);
        model.getColumn(11).setCellRenderer(labelRenderer);
        model.getColumn(13).setCellRenderer(meubleRenderer);
        model.getColumn(14).setCellRenderer(photoRenderer);
    }

    public int rechercheTP() {
        return rechercheTP.getSelectedIndex();
    }
    private JPanel actionP;
    private JComboBox archiveCB;
    private JRadioButton archiveFalseRB;
    private JLabel archiveL;
    private JPanel archiveP;
    private JRadioButton archiveTrueRB;
    private JLabel auL;
    private JPanel avancee;
    private ButtonGroup buttonGroup1;
    private JComboBox categorieCB;
    private JLabel categorieL;
    private JComboBox cuisineCB;
    private JLabel cuisineL;
    private DateComboBox dateAuF;
    private DateComboBox dateDuF;
    private JMenuItem deleteMI;
    private JComboBox disponibiliteCB;
    private JPanel disponibiliteP;
    private JLabel duL;
    private JPanel fields;
    private JComboBox garageCB;
    private JLabel garageL;
    private JComboBox genreCB;
    private JLabel genreL;
    private JMenuItem helpMI;
    private IconBar iconBar1;
    private JLabel infosL;
    private JPanel infosP;
    private JButton initB;
    private JMenuBar jMenuBar1;
    private JScrollPane jScrollPane1;
    private JComboBox jardinCB;
    private JLabel jardinL;
    private JPanel liste;
    private JComboBox meubleCB;
    private JLabel meubleL;
    private JMenuItem modifyMI;
    private JMenuItem newMI;
    private JMenuItem openMI;
    private JComboBox optionCB;
    private JLabel optionL;
    private JMenu options;
    private JComboBox orderByCB;
    private JComboBox parkingCB;
    private JLabel parkingL;
    private JComboBox piscineCB;
    private JLabel piscineL;
    private JMenuItem printMI;
    private JComboBox prixCB;
    private JLabel prixL;
    private JPanel recherche;
    private JTabbedPane rechercheTP;
    private JComboBox reserveCB;
    private JLabel reserveL;
    private JTable resultat;
    private JMenuItem saveMI;
    private JButton searchB;
    private JComboBox secteurCB;
    private JLabel secteurL;
    private JComboBox selectCB;
    private JTextField selectF;
    private JPanel simple;
    private JComboBox standingCB;
    private JLabel standingL;
    private JComboBox typeCB;
    private JLabel typeL;
    private JComboBox visibiliteCB;
    private JLabel visibiliteL;
    private JPanel visibiliteP;
    private JComboBox visibilityCB;
    private DefaultTableCellRenderer optionRenderer;
    private DefaultTableCellRenderer photoRenderer;
    private DefaultTableCellRenderer meubleRenderer;
    private DefaultTableCellRenderer labelRenderer;
    private Color alternateColor;
    private Vector rangees;
    private Vector colonnes;
    private TableModel myModel;
    private WIDate date;
    private String rentPrice[] = {
        "indiff\351rent", "<400", "<500", "<600", "<700", "<800", "<900", "<1000", "<1500", "<2000"
    };
    private String salePrice[] = {
        "indiff\351rent", "<45000", "<75000", "<100000", "<150000", "<200000"
    };
    protected boolean law;
    private Icon lightGreen;
    private Icon darkGreen;
    private Icon lightRed;
    private Icon darkRed;
    private Icon lightYellow;
    private Icon darkYellow;
    private Icon lightOrange;
    private Icon darkOrange;
}
